package com.fengweijie.controller;

import com.fengweijie.service.FileService;
import com.fengweijie.util.Result;
import com.fengweijie.util.ResultCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/file/api")
@CrossOrigin
@Slf4j
public class FileController {

    @Autowired
    private FileService fileService;

    @PostMapping("/upload")
    public Result upload(@RequestBody MultipartFile file) throws IOException {
        String url = fileService.uploadFile(file);
        return new Result(ResultCode.success, "上传成功", url);
    }
}
